// ===============================================
// home_page
//
// Create by Will on 2024/12/4 22:16
// Copyright @flutter_base.All rights reserved.
// ===============================================

import 'package:adaptive_theme/adaptive_theme.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';

import '../../generated/l10n.dart';
import '../../service/app_service.dart';

class HomePage extends ConsumerWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    return CupertinoPageScaffold(
      backgroundColor: Colors.transparent,
      navigationBar: const CupertinoNavigationBar(
        middle: Text('Home'),
      ),
      child: ListView(
        children: [
          ElevatedButton(
            onPressed: () => context.go('/profile/settings'),
            child: const Text('Go to settings'),
          ),
          const SizedBox(height: 10),
          ElevatedButton(
            onPressed: () {
              AdaptiveTheme.of(context).setSystem();
              CupertinoAdaptiveTheme.of(context).setSystem();
            },
            child: Text(AppIntl.of(context).sys_theme),
          ),
          const SizedBox(height: 10),
          ElevatedButton(
            onPressed: () {
              AdaptiveTheme.of(context).setDark();
              CupertinoAdaptiveTheme.of(context).setDark();
            },
            child: Text(AppIntl.of(context).dark_theme),
          ),
          const SizedBox(height: 10),
          ElevatedButton(
            onPressed: () {
              AdaptiveTheme.of(context).setLight();
              CupertinoAdaptiveTheme.of(context).setLight();
            },
            child: Text(AppIntl.of(context).light_theme),
          ),
          const SizedBox(height: 10),
          ElevatedButton(
            onPressed: () =>
                setLocale(languageCode: 'en', countryCode: '', ref: ref),
            child: Text(AppIntl.of(context).language_en),
          ),
          const SizedBox(height: 10),
          ElevatedButton(
            onPressed: () =>
                setLocale(languageCode: 'zh', countryCode: 'CN', ref: ref),
            child: Text(AppIntl.of(context).language_cn),
          ),
          const SizedBox(height: 10),
          ElevatedButton(
            onPressed: () =>
                setLocale(languageCode: 'zh', countryCode: 'HK', ref: ref),
            child: Text(AppIntl.of(context).language_hk),
          ),
        ],
      ),
    );
  }

  /// 设置-语言
  void setLocale({
    required String languageCode,
    required String countryCode,
    required WidgetRef ref,
  }) {
    final language = Locale(languageCode, countryCode);
    ref.read(appLocalizationsProvider.notifier).setLocale(language);
  }
}
